package com.itheima.reggie.common;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 员工存在异常处理
     * @param e
     * @return
     */
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public R<String> SQLException(SQLIntegrityConstraintViolationException e){
        e.printStackTrace();
        return  R.error(e.getMessage().split(" ")[2]+":已存在");
    }

    /**
     * 分类存在套餐或菜品不能删除异常
     * @param e
     * @return
     */
    @ExceptionHandler(CategoryException.class)
    public R<String> SQLException(CategoryException e){
        e.printStackTrace();
        return  R.error(e.getMessage());
    }

    /**
     * 其他异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    public R<String> otherException(Exception e){
        e.printStackTrace();
        return R.error("服务器正在优化升级，请稍后重试QvQ");
    }


}
